#include <unistd.h>
#include <signal.h>
#include <stdio.h>

void sig_alrm(int signo)
{
    printf("%s\n", __FUNCTION__);
}

unsigned int mysleep(unsigned int sec)
{
    struct sigaction new, old;
    unsigned int unslept;

    new.sa_handler = sig_alrm;
    sigemptyset(&new.sa_mask);
    new.sa_flags = 0;
    sigaction(SIGALRM, &new, &old);

    alarm(sec);
    pause();

    unslept = alarm(0);
    sigaction(SIGALRM, &old, NULL);

    return unslept;
}

int main(void)
{
    while(1){
        mysleep(2);
        printf("2 secs passed.\n");
    }
    return 0;
}

